import codecs
import os
import sys

Suffix='.php'
OutFile='./outPaths.txt'

def GetCurrentPath(path:str)->slice:
	"""
	取当前目录文件名列表
	"""
	global Suffix,OutFile
	nub=len(Suffix)
	if os.path.isdir(path):
		with codecs.open(OutFile,mode='w+', encoding='utf-8') as ps:
			for root,dirs,files in os.walk(path):
				for f in files:
					if f.lower()[-1*nub:]==Suffix:
						curpath=os.path.join(root,f)
						curpath=curpath.replace('\\', '/')
						curpath=curpath[1:]
						ps.write(curpath+'\n')
						print(curpath)
		ps.close()

			
if __name__=='__main__':
	if len(sys.argv)>1:
		for idx in range(len(sys.argv)):
			if sys.argv[idx].lower()=='-e' and len(sys.argv)>idx+1:
				Suffix=sys.argv[idx+1]
			if sys.argv[idx].lower()=='-o' and len(sys.argv)>idx+1:
				OutFile=sys.argv[idx+1]
		GetCurrentPath('.')
	else:
		print('='*64)
		print('批量导出指定文件后缀名文件路径，用于目录暴破测试')
		print('用法：')
		print(f'python3 {sys.argv[0]} -e .php -o fileName')
		print('-e 指定要列出的文件后缀名，如：.php; 默认值为.php')
		print('-o 指定输出的文件名，默认为outPaths.txt')
		print('\n提示：必须把本脚本放在需要生成路径的第一级目录下。')
		print('-'*64)

